﻿!DOCTYPE html>
<html lang="zh-cn">
<head>
<title>旺旺集团</title>
﻿<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="alternate icon" type="image/png" href="images/favicon.png">
<link rel='icon' href='favicon.ico' type='image/x-ico' />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" href="css/default.min.css?t=227" />
<!--[if (gte IE 9)|!(IE)]><!-->
<script type="text/javascript" src="lib/jquery/jquery.min.js"></script>
<!--<![endif]-->
<!--[if lte IE 8 ]>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="lib/amazeui/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<script type="text/javascript" src="lib/handlebars/handlebars.min.js"></script>
<script type="text/javascript" src="lib/iscroll/iscroll-probe.js"></script>
<script type="text/javascript" src="lib/amazeui/amazeui.min.js"></script>
<script type="text/javascript" src="lib/raty/jquery.raty.js"></script>
<script type="text/javascript" src="js/main.min.js?t=1"></script>
<link rel="stylesheet" href="layui/css/layui.css">
<script src="js/jquery-1.8.2.js"></script>
<script src="layui/layui.js">
</script>
</head>

<body> 


     <header class="header-article-list">
        <h2>在线留言</h2>

    </header>
	<form class="layui-form">
		<!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
		<div class="layui-form-item">
			<label class="layui-form-label">用户</label>
			<div class="layui-input-block">
				<input type="text" name="yonghu" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">留言内容</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" class="layui-textarea" name="neirong"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
		<!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
	</form>
   
	<script>
		

	 	layui.use('form', function() {
			var form = layui.form;
			$.ajax({
			    url:'liuyanchaxunServlet',
			    dataType:'json',
			    type:'get',
			    success:function(res){
			    	$.each(res.data,function(index,value){
			    		$('#selectID').append("<option value="+value.id+">"+value.name+"</option>");//往下拉菜单里添加元素
			    	})

					form.render();//菜单渲染 把内容加载进去
				}
			})
			
			//各种基于事件的操作，下面会有进一步介绍
			form.on('submit(*)', function(data) {
				console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
				console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
				console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
				//alert("hi");
				data.field.tupian = $("#tupian").attr("src");
				$.ajax({
					url : "liuyanaddServlet",//地址
					type : "get",//请求方式
					data : data.field//参数
					,
					success : function(res) {//成功以后的回调函数
						if (res == 1) {
							alert("添加成功");
							window.location.reload();
						} else {
							alert("添加失败");
						}
					}
				});
				return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		});
	</script>
</body>


 

</html>